// -----------------------------------------------------------------------------
// all group 
// _playtype 参考 RateConfig_5h $this->playGroupArr 对应
// -----------------------------------------------------------------------------
var M = new Object();
M.Rates = new Array();
M.RatesTimeId = 0;
M.rateI = 0; 
$.fn.getAjaxRatedata = function(_lotto_id, _gametype, _playtype){
 if (M.RatesTimeId) { clearTimeout(M.RatesTimeId); }
 $().disAreaObj();
 var tempStr = '';
  //debug window.open('op.php?op=xml_3d&fp=rate_5h&playtype=' + _playtype + '&lotto_id_5h=' + _lotto_id + "&gametype=" + _gametype + "&disk="+ $("select#slcDisk").val() + tempStr );
  $.getJSON('op.php?op=xml_3d&fp=rate_5h&playtype=' + _playtype + '&lotto_id_5h=' + _lotto_id + "&gametype=" + _gametype + "&disk="+ $("select#slcDisk").val() + tempStr ,function(ratedata){
    var dataLen = 0;
    var urlPre = "";
    var hrefStr = "";

    if(ratedata == undefined){
      $("div#errormsg").addClass("error").text("系统维护中");
    }else if(ratedata.errormsg != undefined){
      $("div#errormsg").addClass("error").text("No Rate data");
    }else{
      var xyid = $("select#xyidSlc").val();
      var disk = $("select#slcDisk").val(); 
                           
      //show table & ratedata
      //$().showTableData(ratedata,_lotto_id,_gametype,_playtype,xyid,disk);
      var htmStr="";
      M.rateI = 0;
      switch(_playtype){
         case 'r1':
             htmStr = show_r1(ratedata,_lotto_id,_gametype,_playtype, xyid, disk); break;
         case 'rp1':
         case 'rp2':
         case 'rp3':
         case 'rp4':
         case 'rp5':
         case 'rp6':
         case 'rp7':
         case 'rp8':
         case 'rp9':
         case 'rp10':
             htmStr = show_rpx(ratedata,_lotto_id,_gametype,_playtype, xyid, disk); break;
         default:
             htmStr = 'error show data'; $("#myDivTbl").html(htmStr); return false; break;
      }  
      $("#myDivTbl").html(htmStr);
    }
    
   $().redisAreaObj();   
   $("div#mainPageData").show();
   $("div#errormsg").text("");
   // change text or checkbox type
    var timebtnType = $("input:hidden#timebtnType").val();
    if(timebtnType == "checkbox"){
      $().timebtnTypeToCheckbox();
      $('#setMyNum2').css('display', '');
    }else{
      $('#tblMy3DArea input:text').change(function(){
        var chkVal = $(this).val();
        if(chkVal != ''){ $(this).addTheValClr(null, '') }
        else{ $(this).clrTheValClr(null); }
      });
    }
    
    $("#tblMy3DArea td:has(input)").parent("tr.td2").hover(
      function() {$(this).children().addClass("trover");}
      , function() {$(this).children().removeClass("trover");}
    );
    $('#myreset').click();
    // check rate each 30 sec
    //renewRateTimeObj = setTimeout(function(){$().renewR1data(_lotto_id,_gametype);}, renewRateTime);
    if( _timestap > 0 )
    {
      M.ReNewTime = Math.floor( ( Math.random() * 100 ) % 30 + 30 ) * 1000;
      M.RatesTimeId = setTimeout("$().getAjaxRatedata(" + _lotto_id + "," + _gametype + ",'" + _playtype + "');", M.ReNewTime);
    }else if ( M.RatesTimeId ) { clearTimeout(M.RatesTimeId); }  
    
  });
};

// show table data
// jason data format={"bXX":{"number":["01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21"],
//                          "rates":[1.92,1.92,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00]},

// 主盘势    
function show_r1(rdata,_lotto_id,_gametype,_playtype, xyid, disk){
  var strTbl = "<table width='800px' border='0'>";
  /*var strTbl = "<table class='tblMy3D' width='990' >";
  strTbl += '<tr class="bgClc_' + _gametype + '"><th>名</th><th>项目</th><th>赔率</th><th>金额</th><th>项目</th><th>赔率</th><th>金额</th><th>项目</th><th>赔率</th><th>金额</th><th>项目</th><th>赔率</th><th>金额</th><th>项目</th><th>赔率</th><th>金额</th><th>项目</th><th>赔率</th><th>金额</th></tr>';*/
  var rArr = "";
  var rArrA = "";
  var betArr = "";
  var showTitleArr = "";
  // 单双大小
  var showTitleArr = [['单', '双'], ['大', '小'], ['龙', '虎']];       
  var showTitleArr01 = [['合单', '合双'], ['合大', '合小']];

  var showBetSubArr = [
       ['冠', [rdata.b1_1 , rdata.b2_1 , rdata.b6_1], [1,2,6],[1,1,1], showTitleArr,1,'']
      ,['亚', [rdata.b1_2 , rdata.b2_2 , rdata.b6_2], [1,2,6],[2,2,2], showTitleArr,1,'']
      ,['季', [rdata.b1_3 , rdata.b2_3 , rdata.b6_3], [1,2,6],[3,3,3], showTitleArr,1,'']
      ,['四', [rdata.b1_4 , rdata.b2_4 , rdata.b6_4], [1,2,6],[4,4,4], showTitleArr,1,'']
      ,['五', [rdata.b1_5 , rdata.b2_5 , rdata.b6_5], [1,2,6],[5,5,5], showTitleArr,1,'']
      ,['六', [rdata.b1_6 , rdata.b2_6], [1,2],[6,6], showTitleArr,1,'']
      ,['七', [rdata.b1_7 , rdata.b2_7], [1,2],[7,7], showTitleArr,1,'']
      ,['八', [rdata.b1_8 , rdata.b2_8], [1,2],[8,8], showTitleArr,1,'']
      ,['九', [rdata.b1_9 , rdata.b2_9], [1,2],[9,9], showTitleArr,1,'']
      ,['十', [rdata.b1_10 ,rdata.b2_10],[1,2],[10,10], showTitleArr,1,'']
      ,['冠亚', [rdata.b3_0 , rdata.b4_0], [3,4],[0,0], showTitleArr01,1,'']
    ];
  // 单双,大小
  var oShow = '';
  strTbl+="<tr>";
  var l = showBetSubArr.length-1;
  for(var i = 0; i < l; i++){
    oShow = showBetSubArr[i];
	strTbl+="<td><table class='tblMy3D' style='width:158px!important'><tr><th colspan=3 class='bgImg_24'>"+oShow[0]+"</th></tr>";
	strTbl += crt_2face_com_new(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
	strTbl+="</table></td>";
	if(i==4) strTbl+="</tr><tr>";
  }
  oShow = showBetSubArr[10];
  strTbl+="<tr><td colspan=5><table class='tblMy3D'><tr><th colspan=12 class='bgImg_24'>"+oShow[0]+"</th></tr>";
  strTbl += crt_2face_com(oShow[1], oShow[2], oShow[3], "", oShow[4], oShow[5], 4, disk, _playtype, oShow[6],xyid);
  strTbl+="</table></td></tr>";
  /*for(var i = 0; i < l; i++){
    oShow = showBetSubArr[i];
    strTbl += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
  }*/
  strTbl += "</tr></table>";
  $("#myDivTbl").html(strTbl);
}

function show_rpx(rdata,_lotto_id,_gametype,_playtype, xyid, disk){
  var sStr = '<table class="tblMy3D" id="tblMy3DArea" width="700">';
  var showBetSubArr = '';
  var i = 0;
  var l = 0;
  var oShow = '';
  var showTitleArr = [['单', '双'], ['大', '小']];       
  var showTitleArr01 = [['龙', '虎'],['','']];       
  var showTitleArr02 = [['合单', '合双'], ['合大', '合小']];       
  var subidArr = '';
  var sTitle = '';
  var subidShow = '';
  var oShow = '';
  var showBetSubArr='';
  switch(_playtype){
    case 'rp1':  
      sTitle = '冠军';subid = 1;
      sStr += crt_1To21(rdata.b0_1, 0, subid, sTitle, 2, disk, _playtype, xyid);
      oShow = ['', [rdata.b1_1, rdata.b2_1], [1,2], [subid,subid], showTitleArr  , 1, ''];
      sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
      oShow = ['', [rdata.b6_1]            , [6]  , [subid]  , showTitleArr01, 1, ''];
      sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
      sTitle = '';subid = 2;
      sStr += '<tr><th colspan="18" class="bgClc_' + _gametype + '" style="font-family:Arial;font-size:0.9em;">亚军</th></tr>';
      sStr += crt_1To21(rdata.b0_2, 0, subid, sTitle, 2, disk, _playtype, xyid);
      oShow = ['', [rdata.b1_2, rdata.b2_2], [1,2], [subid,subid], showTitleArr  , 1, ''];
      sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
      oShow = ['', [rdata.b6_2]            , [6]  , [subid]  , showTitleArr01, 1, ''];
      sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
      sStr += '<tr><th colspan="18" class="bgClc_' + _gametype + '" style="font-family:Arial;font-size:0.9em;">冠亚,和值</th></tr>';
      sStr += crt_1To21(rdata.b5_0, 5, 0, '', 4, disk, _playtype, xyid);
      oShow =  ['', [rdata.b3_0, rdata.b4_0], [3,4], [0,0], showTitleArr02, 1, ''];
      sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
      break;
   
    case 'rp3': 
      sTitle = '季军';subid = 3;
      sStr += crt_1To21(rdata.b0_3, 0, subid, sTitle, 2, disk, _playtype, xyid);
      oShow = ['', [rdata.b1_3, rdata.b2_3], [1,2], [subid,subid], showTitleArr  , 1, ''];
      sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
      oShow = ['', [rdata.b6_3]            , [6]  , [subid]  , showTitleArr01, 1, ''];
      sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
      sTitle = '';subid = 4;
      sStr += '<tr><th colspan="18" class="bgClc_' + _gametype + '" style="font-family:Arial;font-size:0.9em;">第四</th></tr>';
      sStr += crt_1To21(rdata.b0_4, 0, subid, sTitle, 2, disk, _playtype, xyid);
      oShow = ['', [rdata.b1_4, rdata.b2_4], [1,2], [subid,subid], showTitleArr  , 1, ''];
      sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
      oShow = ['', [rdata.b6_4]            , [6]  , [subid]  , showTitleArr01, 1, ''];
      sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
      break;
    case 'rp5':  
      sTitle = '第五';subid = 5;
      sStr += crt_1To21(rdata.b0_5, 0, subid, sTitle, 2, disk, _playtype, xyid);
      oShow = ['', [rdata.b1_5, rdata.b2_5], [1,2], [subid,subid], showTitleArr  , 1, ''];
      sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
      oShow = ['', [rdata.b6_5]            , [6]  , [subid]  , showTitleArr01, 1, ''];
      sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
      sTitle = '';subid = 6;
      sStr += '<tr><th colspan="18" class="bgClc_' + _gametype + '" style="font-family:Arial;font-size:0.9em;">第六</th></tr>';
      sStr += crt_1To21(rdata.b0_6, 0, subid, sTitle, 2, disk, _playtype, xyid);
      oShow = ['', [rdata.b1_6, rdata.b2_6], [1,2], [subid,subid], showTitleArr  , 1, ''];
      sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
      break;
    case 'rp7':
      sTitle = '第七';subid = 7;
      sStr += crt_1To21(rdata.b0_7, 0, subid, sTitle, 2, disk, _playtype, xyid);
      oShow = ['', [rdata.b1_7, rdata.b2_7], [1,2], [subid,subid], showTitleArr  , 1, ''];
      sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
      sTitle = '';subid = 8;
      sStr += '<tr><th colspan="18" class="bgClc_' + _gametype + '" style="font-family:Arial;font-size:0.9em;">第八</th></tr>';
      sStr += crt_1To21(rdata.b0_8, 0, subid, sTitle, 2, disk, _playtype, xyid);
      oShow = ['', [rdata.b1_8, rdata.b2_8], [1,2], [subid,subid], showTitleArr  , 1, ''];
      sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
      break;
    case 'rp9':  
      sTitle = '第九';subid = 9;
      sStr += crt_1To21(rdata.b0_9, 0, subid, sTitle, 2, disk, _playtype, xyid);
      oShow = ['', [rdata.b1_9, rdata.b2_9], [1,2], [subid,subid], showTitleArr  , 1, ''];
      sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
      sTitle = '';subid = 10;
      sStr += '<tr><th colspan="18" class="bgClc_' + _gametype + '" style="font-family:Arial;font-size:0.9em;">第十</th></tr>';
      sStr += crt_1To21(rdata.b0_10, 0, subid, sTitle, 2, disk, _playtype, xyid);
      oShow = ['', [rdata.b1_10, rdata.b2_10], [1,2], [subid,subid], showTitleArr  , 1, ''];
      sStr += crt_2face_com(oShow[1], oShow[2], oShow[3], oShow[0], oShow[4], oShow[5], 5, disk, _playtype, oShow[6],xyid);
      break;
    default :  return '-rpn error-'; 
  }

  sStr += '</table>';
  return sStr;
}

$.fn.addTheValClr = function(attVal1, attVal2){
  if(attVal1 == null){ $(this).css('background-color', '#ffff8c'); }
  else{ $(this).css('background-color', '#ffff8c').attr(attVal1, attVal2); }
};

$.fn.clrTheValClr = function(attVal1){
  if(attVal1 != null){ $(this).removeAttr(attVal1); }
  $(this).removeAttr('disabled').css('background-color', '');
  
}
function crt_2face_com_new(rdata, bettype, subBettype, sTitle, showTitleArr, rowSpanN, tdNum, disk,playgroup, bgClass,xyid){
  var setBtnId = "";
  var str = '';
  var strTitle = "";
  var sNum = "";
  var sRate = "";
  var num = 0;
  var setBtnId = "";
  var nextI = -1;        // 可秀玩法
  var i = 0;
  var l = 0;
  var l2 = 0;
  var littletotal = 0;
  var classCount = 0;
  var titleTemp = '';
  var colTemp = '';
  var tempCount = 0;
  var urlPre = '';
  var showClass = '';
  var rateClass = "";
  var inpVal = "";
  str = '';
  for(i = 0, l = rdata.length; i < l; i++ ){
    l2 = showTitleArr[i].length;
    for(var j = 0; j < l2; j++){  // 双面
      tempCount++;
      sNum = rdata[i].number[j];
      sRate = rdata[i].rates[j];
      setBtnId = setBtnId = 'b_' + subBettype[i] + '_' +  bettype[i] + '_' + sNum;
      urlPre = 'op.php?op=member_5h&fp=bet_fast&gametype=' + _gametype + '&disk=' + disk + '&palygroup=' + playgroup + '&bettype=' + bettype[i] + '&subid=' + subBettype[i] + '&num=' + sNum+ '&xyid=' + xyid + '&rate=' + sRate;
      if(bgClass != ''){ showClass = ' ' + bgClass + sNum; }else{ showClass = ''; }
      if( M.Rates[M.rateI] == undefined ) { rateClass = ''; }
      else if( M.Rates[M.rateI] != sRate ) { rateClass = ' class="rc"'; }
      else { rateClass = ''; }
      M.Rates[M.rateI] = sRate;
      M.rateI++;
      inpVal = $('input[name="' + setBtnId + '"]').val();
      if( inpVal == undefined ) { inpVal = ''; }
      str += '<tr class="td2"><th style="width:30px;height30px" class="title02_3d' + showClass + '" nowrap>' + showTitleArr[i][j] + '</th>';
      str += '<th' + rateClass + ' style="width:40px;"><a href="' + urlPre + '" class="betRateNum" target="leftFrame">' + sRate + '</a></th>';
      str += '<td  style="width:50px;"><input type="text" size="3"  value="' + inpVal + '" name="' + setBtnId + '" /></td></tr>';  
    }
  }
  /*if(tempCount < tdNum){
   for(i = 0; i < (tdNum - tempCount); i++){
    str += '<td></td><td></td><td></td>';
   }
  }*/
  return str;

}
//两面
function crt_2face_com(rdata, bettype, subBettype, sTitle, showTitleArr, rowSpanN, tdNum, disk,playgroup, bgClass,xyid){
  var setBtnId = "";
  var str = '';
  var strTitle = "";
  var sNum = "";
  var sRate = "";
  var num = 0;
  var setBtnId = "";
  var nextI = -1;        // 可秀玩法
  var i = 0;
  var l = 0;
  var l2 = 0;
  var littletotal = 0;
  var classCount = 0;
  var titleTemp = '';
  var colTemp = '';
  var tempCount = 0;
  var urlPre = '';
  var showClass = '';
  var rateClass = "";
  var inpVal = "";
  str = '<tr class="td2">' + (sTitle!='' ? '<td class="td15">' + sTitle + '</td>' : '' );
  for(i = 0, l = rdata.length; i < l; i++ ){
    l2 = showTitleArr[i].length;
    for(var j = 0; j < l2; j++){  // 双面
      tempCount++;
      sNum = rdata[i].number[j];
      sRate = rdata[i].rates[j];
      setBtnId = setBtnId = 'b_' + subBettype[i] + '_' +  bettype[i] + '_' + sNum;
      urlPre = 'op.php?op=member_5h&fp=bet_fast&gametype=' + _gametype + '&disk=' + disk + '&palygroup=' + playgroup + '&bettype=' + bettype[i] + '&subid=' + subBettype[i] + '&num=' + sNum+ '&xyid=' + xyid + '&rate=' + sRate;
      if(bgClass != ''){ showClass = ' ' + bgClass + sNum; }else{ showClass = ''; }
      if( M.Rates[M.rateI] == undefined ) { rateClass = ''; }
      else if( M.Rates[M.rateI] != sRate ) { rateClass = ' class="rc"'; }
      else { rateClass = ''; }
      M.Rates[M.rateI] = sRate;
      M.rateI++;
      inpVal = $('input[name="' + setBtnId + '"]').val();
      if( inpVal == undefined ) { inpVal = ''; }
      str += '<th class="title02_3d' + showClass + '" nowrap>' + showTitleArr[i][j] + '</th>';
      str += '<th' + rateClass + '><a href="' + urlPre + '" class="betRateNum" target="leftFrame">' + sRate + '</a></th>';
      str += '<td style="width:50px;"><input type="text" size="3"  value="' + inpVal + '" name="' + setBtnId + '" /></td>';  
    }
  }
  if(tempCount < tdNum){
   for(i = 0; i < (tdNum - tempCount); i++){
    str += '<td></td><td></td><td></td>';
   }
  }
  return str;

}

// n1~n5 - money
function crt_1To21(rdata, bettype, subid, sTitle, iNumTr, disk, playgroup,xyid){
  var str = "";
  var urlPre = "";
  var setBtnId = "";
  var htmlTemp = '<tr class="td2">';
  var htmlTitle = '<th>号码</th><th>赔率</th><th>金额</th>';
  var trArr = new Array();
  var idx = 0;
  var dataLen = rdata.number.length;
  var i = 0;                
  for(i = 0; i < iNumTr; i++){ trArr[i] = '';} 
  var oNum = 0;
  var oRate = 0;              
  var showTitleN = Math.floor(dataLen / iNumTr);
  var numClass = '';
  var numClassN = 0;  
  var rateClass = "";
  var inpVal = "";
  if((dataLen % iNumTr) > 0){showTitleN += 1; }
  if(sTitle!=''){           
    str += '<caption class="bgClc_' + _gametype   + '">' + sTitle + '</caption>';
  }
  str += '<thead><tr class="td15">';
  for(i = 0; i < showTitleN; i++){ str += htmlTitle; }
  str += '</tr></thead>';
  str += '<tbody align=center id="tbdData">';
  for(i = 0; i < dataLen; i++){
    idx = i % iNumTr;
    oNum = rdata.number[i];
    oRate = rdata.rates[i];
    urlPre = 'op.php?op=member_5h&fp=bet_fast&gametype=' + _gametype + '&disk=' + disk + '&palygroup=' + playgroup + '&bettype=' + bettype + '&subid=' + subid + '&num=' + oNum + '&xyid=' + xyid + '&rate=' + oRate;
    setBtnId = 'b_' + subid + '_' +  bettype + '_' + oNum;
    //numClassN = oNum % 4;
    //if(numClassN == 0 ){numClassN = 4; }
    switch (oNum)
    {
        case "03":
        case "04":
        case "18":
        case "19":
            numClassN = 1;
            break;
        case "05":
        case "06":
        case "16":
        case "17":
            numClassN = 2;
            break;  
        case "07":
        case "08":
        case "14":
        case "15":
            numClassN = 3;
            break;    
        case "09":
        case "10":
        case "12":
        case "13":
            numClassN = 4;
            break;
        default:
            numClassN = 5;                                                
    }
      
    numClass = 'four5hB0' + numClassN;
    
    if (dataLen <= 10)
    {
        trArr[idx] += '<th><img src="image/pk' + (oNum - 0) + '.png"></th>';
    }
    else
    {
        trArr[idx] += '<th class="title02_3d ' + numClass + '">' + oNum + '</th>';
    }
    
    if( M.Rates[M.rateI] == undefined ) { rateClass = ''; }
    else if( M.Rates[M.rateI] != oRate ) { rateClass = ' class="rc"';  }
    else { rateClass = ''; }
    M.Rates[M.rateI] = oRate;
    M.rateI++;
    inpVal = $('input[name="' + setBtnId + '"]').val();
    if( inpVal == undefined ) { inpVal = ''; }
    trArr[idx] += '<th' + rateClass + '><a href="' + urlPre + '" class="betRateNum" target="leftFrame">' + oRate + '</a></th>';
    trArr[idx] += '<td><input type="text" size="3"  value="' + inpVal + '" name="' + setBtnId + '" /></td>'; 
  }
  if(idx++ != iNumTr){
    for(i = idx; i < iNumTr; i++){
      trArr[i] += '<td></td><td></td><td></td>';
    }
  }
  str += htmlTemp + trArr.join('</tr><tr class=td2>') + '</tr>';
  str += '</tbody>';
  return str;
}

// -----------------------------------------------------------------------------
// function
// -----------------------------------------------------------------------------

// change money input to fast checkbox button 
$.fn.timebtnTypeToCheckbox = function(){
	mysetcookie("timebtnType","checkbox",1);
  $("input:hidden#timebtnType").val("checkbox");
  $("#myDivTbl input:text[name^='b_']").each(function(){
    var o=$(this).closest('td');
		o.html("<input type=\"checkbox\" value=\"1\" name=\"" + $(this).attr("name") + "\" style=\"display:none\" />");
		o.bind("click",function(e){
			var inpu=$(this).find("input");
			if(inpu.attr("checked"))
			{
				$(this).removeClass("k1");	
				inpu.attr("checked",false);
			}
			else
			{
				$(this).addClass("k1");	
				inpu.attr("checked",true);
			}
		});
    return true;
  });
  $("input:button#betByCheckBox").addClass("btn_on");
    $("input:button#betByTextMoney").removeClass("btn_on");
  //$("input:button#betByCheckBox").hide();
  //$("input:button#betByTextMoney").show();
  $("input:button#btnSetMyNum").attr("disabled","true");
};

// chang fast to money input
$.fn.timebtnTypeText = function(){
	mysetcookie("timebtnType","text",1);
  $("input:hidden#timebtnType").val("text");
  $("input:checkbox[name^='b_']").each(function(){
    var o=$(this).closest('td');
		o.html("<input type=\"text\" value=\"\" name=\"" + $(this).attr("name") + "\" size=\"3\" />");
		o.removeClass("k1");
		o.unbind("click");
        return true;
    return true;
  });
  $("input:button#betByTextMoney").addClass("btn_on");
    $("input:button#betByCheckBox").removeClass("btn_on");
 // $("input:button#betByTextMoney").hide();
 // $("input:button#betByCheckBox").show();
  $("input:button#btnSetMyNum").removeAttr("disabled");
};
function leftPar(v)
{
	if(parseInt(v)<=9)
		return "0"+v;
	else
		return v;	
}
var _refstap=30;
$.fn.showNowTime = function(){
  var thisObj = $(this);
  var str = "";
    if (_timestap >= 0) {
        timediff = _timestap;
    days = Math.floor(timediff / (86400));   // 60 * 60 * 24
  	timediff -= days * (86400);
  	hours = Math.floor(timediff / (3600));  // 60 * 60
  	timediff -= hours * (3600);	
  	mins = Math.floor(timediff / (60));
  	timediff -= mins * (60);	
  	secs = Math.floor(timediff);
    str += "<span style='margin-right:10px'><div style='float:left;width:150px'>距离封盘：";
    if (days > 0 ) str += "<b>" + leftPar(days) + "</b> 天 ";
    if (hours > 0) str += "<b>" + leftPar(hours) + "</b>:";
    if (mins > 0) str += "<b>" + leftPar(mins) + "</b>:";
    str += "<b>" + leftPar(secs) + "</b></div><div style='float:left;width:150px'>距离开奖：";
	//
	timediff2=_timestap+60;
	days = Math.floor(timediff2 / (86400));   // 60 * 60 * 24
  	timediff2 -= days * (86400);
  	hours = Math.floor(timediff2 / (3600));  // 60 * 60
  	timediff2 -= hours * (3600);	
  	mins = Math.floor(timediff2 / (60));
	timediff2 -= mins * (60);	
  	secs = Math.floor(timediff2);
	if (days > 0 ) str += "<b>" + leftPar(days) + "</b> 天 ";
    if (hours > 0) str += "<b>" + leftPar(hours) + "</b>:";
    if (mins > 0) str += "<b>" + leftPar(mins) + "</b>:";
	str += "<b>" + leftPar(secs) + "</b></div><div style='float:left;width:50px;text-align:right;'>"+leftPar(_refstap)+"秒</div></span>";
	_refstap--;
	if(_refstap==0) _refstap=30;
    _timestap-=1;
  }else{
    str += "<font color=red><b>【" + _gametypeStr + "】已经截止下注！</b></font>";
    if ( M.RatesTimeId ) { clearTimeout(M.RatesTimeId); }
    setTimeout('parent.mainFrame.location.reload()',1000);
    setTimeout('parent.leftFrame.location.reload()',1000);
  }
  $(this).html(str);
  _now.setTime(_now.getTime() + 1000);
  setTimeout(function(){$(thisObj).showNowTime();},1000);
};

// 显示讯息方块(取代alert 因alert会使目前时间与截止下注时间暂时停止计算)
$.fn.showMyMsgBox = function(msg){
  $("div#show3dmsg").html("<span class=\"error3d\">"+msg+"</span><br /><input type=\"button\" align=\"center\" id=\"btnOkMsg\" class=\"btnchoice\" value=\"确定\" onclick=\"javascript:$().closeMyMsgBox();\" />");
  $("div#show3dmsg").addClass("show3dmsg").show();
};

$.fn.closeMyMsgBox = function(){
 $("div#show3dmsg").removeClass("show3dmsg").hide();
};

//  更新率赔率禁止使用
$.fn.disAreaObj = function(){
 $("select#xyidSlc").attr("disabled","disabled");
 $("select#slcDisk").attr("disabled","disabled");
 $("input:button#betByCheckBox").attr("disabled","disabled");
 $("input:button#betByTextMoney").attr("disabled","disabled");
};

$.fn.redisAreaObj = function(){
 $("select#xyidSlc").removeAttr("disabled");
 $("select#slcDisk").removeAttr("disabled");
 $("input:button#betByCheckBox").removeAttr("disabled");
 $("input:button#betByTextMoney").removeAttr("disabled");
};

// -----------------------------------------------------------------------------
$(function(){
  
  $("input#disk").attr("value",$("select#slcDisk option:selected").val());

  //if($("input:hidden#timebtnType").val() == "text"){$("input:button#betByTextMoney").hide();}else{$("input:button#betByCheckBox").hide();}
                    
  // time of now
  $("span#showNowTime").showNowTime();
  
  $("div#mainPageData").hide();
  
  // get rate data and show table
  $().getAjaxRatedata(_lotto_id,_gametype,_playtype);
  
  // change to money input
  $("input:button#betByCheckBox").bind('click',function(){
    $().timebtnTypeToCheckbox();
  });
  // change to fast checkbox 
  $("input:button#betByTextMoney").bind('click',function(){$().timebtnTypeText();});
  
  // “transfer”
  $("input:button#btnSetMyNum").bind('click', function(){
    var setMomney = $("input:text#setMomney").val();
    if(setMomney< 1){
      $().showMyMsgBox("请于“金额”右侧之文字方块中输入要转送之金额");
      $("input:text#setMomney").focus();
      return false;
    }else if(setMomney< _betmin){
      $().showMyMsgBox("下注金额不能小于最低下注额("+_betmin+"元)");
      $("input:text#setMomney").focus();
      return false;
    }else{
      $("input:text[name^='b'][value='*']").val(setMomney);
      $("input:text#setMomney").val("");
    } 
  });
  
  // before submit
  $("form").submit(function() {
    switch($("input:hidden#timebtnType").val()){
      case "text": //text
      if($("input:text[name^='b_'][value!='']").not("[value='*']").size() < 1){
        $().showMyMsgBox("请在文字方块中填入要下注的金额；<br />或使用“转送”钮将“*”字转为金额值");
        return false;
      }
      break;
      
      case "checkbox": // checkbox
      if($("input:checkbox[name^='b_']:checked").size() < 1){
        $().showMyMsgBox("请勾选要下注的内容");
        return false;
      }else if($("input:text#setMomney").val()< 1){
        $().showMyMsgBox("请于“金额”右侧之文字方块中输入下注金额");
        $("input:text#setMomney").focus();
        return false;
      }else if($("input:text#setMomney").val()< _betmin){
        $().showMyMsgBox("下注金额不能小于最低下注额("+_betmin+"元)");
        $("input:text#setMomney").focus();
        return false;
      }else {
        $("input:checkbox[name^='b_']:checked").val($("input:text#setMomney").val())
      } 
      break;
    }
    $("form input:submit").add("form input:button").attr("disabled","disabled");
    $("input#disk").attr("value",$("select#slcDisk option:selected").val());
    return true;
  });
  
  $("input:button").hover(
      function() {this.style.color='#0000FF';}
      , function() {this.style.color='';}
  );

  // change rate by a,b,c,d disk
  $("select#slcDisk").change(function(){
    if (M.RatesTimeId) { clearTimeout(M.RatesTimeId); }
    $("input#disk").attr("value",$("select#slcDisk option:selected").val());
    M.Rates = new Array();
    $().getAjaxRatedata(_lotto_id,_gametype,_playtype);
  });
  
  // reset button
  $("input#myreset").click(function(){
    var timebtnType = $("input:hidden#timebtnType").val();
    var attVal1 = '';
    switch(timebtnType){
      case 'text': attVal1 = 'value'; break;
      case 'checkbox': attVal1 = 'checked'; break;
      default: alert('error type'); return false;
    }
    var oObj = $("#tbdData input:[name^='b_']");   
    oObj.clrTheValClr(attVal1);
    if($("#tblMy3DAreaS").length > 0){ $("#tblMy3DAreaS input:[name^='b_']").clrTheValClr('checked'); }
    $('input.quick5hType:checked').click();
  });
  
  // show fast bet button
  
  // show number tbl
  if(_playtype != 'rc' && chgBallArr.length > 0){
    $('.disClc').click(function(){
      $('.onClc').removeClass('onClc');
      $(this).addClass("onClc");  
      var myIDX = $(this).attr("id").substr(5);
      $('#chgBallAreaStr').empty().append(chgBallArr[myIDX]);
      $('#chgBallAreaStr td:even').css("background-color", "#e7ebef");
    });
    $('.disClc:eq(0)').click();
    if(_maxTotal > 0){
      $('#maxDisBall td').each(function(idx, ele){
        if($(ele).text() == _maxTotal){
          $(ele).css({'color':'#FA0300','font-weight':'900'});
        }                                
      });
    }
    if(_maxTotal0 > 0){
      $('#maxDisBall0 td').each(function(idx, ele){
        if($(ele).text() == _maxTotal0){
          $(ele).css({'color':'#FA0300','font-weight':'900'});
        }                                
      });
    }
  }
}); 
$(document).ready(function(e) {
    $("#myreset").bind("click",function(){$(".k1").removeClass("k1");});
});